package com.patrol.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.patrol.pojo.Patrol;
import com.patrol.service.PatrolService;
import com.patrol.utils.Result;
import com.patrol.utils.TableMap;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.Date;

@CrossOrigin
@RestController
@RequestMapping("/api/patrol")
public class PatrolController {
    @Resource
    private PatrolService patrolService;

    @GetMapping("/selectPage")
    public TableMap selectPage(long page, long limit) {
        Page<Patrol> patrolPage = patrolService.selectPage(page, limit);
        TableMap tableMap = new TableMap();
        tableMap.setData(patrolPage.getRecords());
        tableMap.setCount(patrolPage.getTotal());
        return tableMap;
    }

    @GetMapping("/exportData/{startTime}/{endTime}")
    public void exportData(HttpServletResponse response,
                           @PathVariable("startTime") String startTime,
                           @PathVariable("endTime") String endTime) {
        patrolService.exportDataByDate(response, startTime, endTime);
    }
}
